var n = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(n) {
    return typeof n;
} : function(n) {
    return n && "function" == typeof Symbol && n.constructor === Symbol && n !== Symbol.prototype ? "symbol" : typeof n;
};

!function(t, e) {
    "object" == ("undefined" == typeof exports ? "undefined" : n(exports)) && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : t.Ald = e();
}(void 0, function() {
    function t() {
        "function" == typeof ln && "" === T && ln().then(function(n) {
            28 === n.length && (T = n, wx.setStorageSync("aldstat_op", n));
        });
    }
    function e(n) {
        this.app = n;
    }
    function o(n) {
        H = y(), Q = n, sn = n.scene, this.aldstat = new e(this);
    }
    function a(n) {
        t();
        var e;
        e = n.scene != sn, sn = n.scene, N = 0, Q = n, G = n.query.ald_share_src, V = n.query.aldsrc || "", 
        W = n.query.ald_share_src, an || rn || fn || (J = !1), an = !1, (0 !== E && Date.now() - E > 3e4 || e) && (rn || (C = y(), 
        U = Date.now(), hn = 0)), 0 !== E && Date.now() - E < 3e4 && (Z = !0), n.query.ald_share_src && "1044" == n.scene && n.shareTicket ? wx.getShareInfo({
            shareTicket: n.shareTicket,
            success: function(n) {
                z = n, q("event", "ald_share_click", JSON.stringify(n));
            }
        }) : n.query.ald_share_src && q("event", "ald_share_click", 1), "" === F && wx.getSetting({
            withCredentials: !0,
            success: function(n) {
                n.authSetting["scope.userInfo"] && wx.getUserInfo({
                    withCredentials: !0,
                    success: function(n) {
                        var t = g();
                        F = n, t.ufo = m(n), B = v(n.userInfo.avatarUrl.split("/")), w(t);
                    }
                });
            }
        }), x("app", "show");
    }
    function r() {
        t(), E = Date.now(), "" === F && wx.getSetting({
            success: function(n) {
                n.authSetting["scope.userInfo"] && wx.getUserInfo({
                    withCredentials: !0,
                    success: function(n) {
                        F = n, B = v(n.userInfo.avatarUrl.split("/"));
                        var t = g();
                        t.ufo = m(n), w(t);
                    }
                });
            }
        }), x("app", "hide");
    }
    function s(n) {
        $++, q("event", "ald_error_message", n);
    }
    function i(n) {
        en = n;
    }
    function c() {
        un = Date.now(), nn = R ? this.$mp.page.route : this.route, D("page", "show"), Z = !1;
    }
    function u() {
        tn = nn, hn = Date.now() - un;
    }
    function h() {
        tn = nn, hn = Date.now() - un;
    }
    function f() {
        q("event", "ald_pulldownrefresh", 1);
    }
    function l() {
        q("event", "ald_reachbottom", 1);
    }
    function p(n) {
        rn = !0;
        var t = S(n.path), e = {};
        for (var o in Q.query) "ald_share_src" !== o && "ald_share_op" !== o || (e[o] = Q.query[o]);
        var a = "";
        if (a = -1 == n.path.indexOf("?") ? n.path + "?" : n.path.substr(0, n.path.indexOf("?")) + "?", 
        "" !== t) for (var o in t) e[o] = t[o];
        e.ald_share_src ? -1 == e.ald_share_src.indexOf(K) && e.ald_share_src.length < 200 && (e.ald_share_src = e.ald_share_src + "," + K) : e.ald_share_src = K, 
        b.useOpen && (e.ald_share_op ? -1 == e.ald_share_op.indexOf(T) && e.ald_share_op.length < 200 && (e.ald_share_op = e.ald_share_op + "," + T) : e.ald_share_op = T);
        for (var r in e) -1 == r.indexOf("ald") && (a += r + "=" + e[r] + "&");
        return n.path = a + (b.useOpen ? "ald_share_op=" + e.ald_share_op + "&" : "") + "ald_share_src=" + e.ald_share_src, 
        q("event", "ald_share_status", n), n;
    }
    function d() {
        function n() {
            return Math.floor(65536 * (1 + Math.random())).toString(16).substring(1);
        }
        return n() + n() + n() + n() + n() + n() + n() + n();
    }
    function w(n) {
        function t() {
            return new Promise(function(t, e) {
                var o = {
                    AldStat: "MiniApp-Stat",
                    se: j || "",
                    op: T || "",
                    img: B
                };
                "" === L || (o.ai = L), wx.request({
                    url: "https://" + P + ".aldwx.com/d.html",
                    data: n,
                    header: o,
                    method: "GET",
                    success: function(n) {
                        t(200 == n.statusCode ? "" : "status error");
                    },
                    fail: function() {
                        t("fail");
                    }
                });
            });
        }
        N++, n.at = C, n.uu = K, n.v = M, n.ak = b.app_key.replace(/(\t)|(\s)/g, ""), n.wsr = Q, 
        n.ifo = J, n.rq_c = N, n.ls = H, n.te = k, n.et = Date.now(), n.st = Date.now(), 
        b.useOpen ? "" === T ? cn.push(t) : (wx.Queue.push(t), cn.concat()) : wx.Queue.push(t);
    }
    function g() {
        var n = {};
        for (var t in X) n[t] = X[t];
        return n;
    }
    function v(n) {
        for (var t = "", e = 0; e < n.length; e++) n[e].length > t.length && (t = n[e]);
        return t;
    }
    function y() {
        return "" + Date.now() + Math.floor(1e7 * Math.random());
    }
    function m(n) {
        var t = {};
        for (var e in n) "rawData" != e && "errMsg" != e && (t[e] = n[e]);
        return t;
    }
    function S(n) {
        if (-1 == n.indexOf("?")) return "";
        var t = {};
        return n.split("?")[1].split("&").forEach(function(n) {
            var e = n.split("=")[1];
            t[n.split("=")[0]] = e;
        }), t;
    }
    function _(t) {
        for (var e in t) if ("object" == n(t[e]) && null !== t[e]) return !0;
        return !1;
    }
    function x(n, t) {
        var e = g();
        e.ev = n, e.life = t, e.ec = $, e.dr = Date.now() - U, "show" == t && (e.uo = b.useOpen), 
        V && (e.qr = V, e.sr = V), G && (e.usr = G), w(e);
    }
    function D(n, t) {
        var e = g();
        e.ev = n, e.life = t, e.pp = nn, e.pc = tn, e.dr = Date.now() - U, (rn || fn) && (e.so = 1), 
        fn = !1, rn = !1, en && "{}" != JSON.stringify(en) && (e.ag = en), V && (e.qr = V, 
        e.sr = V), G && (e.usr = G), Z && (e.ps = 1), Y ? e.pdr = hn : (on = nn, Y = !0, 
        e.ifp = Y, e.fp = nn, e.pdr = 0), w(e);
    }
    function q(n, t, e) {
        var o = g();
        o.ev = n, o.tp = t, o.dr = Date.now() - U, e && (o.ct = e), w(o);
    }
    function A(n, t, e) {
        if (n[t]) {
            var o = n[t];
            n[t] = function(n) {
                e.call(this, n, t), o.call(this, n);
            };
        } else n[t] = function(n) {
            e.call(this, n, t);
        };
    }
    function O(n) {
        var t = {};
        for (var e in n) "onLaunch" !== e && "onShow" !== e && "onHide" !== e && "onError" !== e && (t[e] = n[e]);
        return t.onLaunch = function(t) {
            o.call(this, t), "function" == typeof n.onLaunch && n.onLaunch.call(this, t);
        }, t.onShow = function(t) {
            a.call(this, t), n.onShow && "function" == typeof n.onShow && n.onShow.call(this, t);
        }, t.onHide = function() {
            r.call(this), n.onHide && "function" == typeof n.onHide && n.onHide.call(this);
        }, t.onError = function(t) {
            s.call(this, t), n.onError && "function" == typeof n.onError && n.onError.call(this, t);
        }, t;
    }
    function I(n) {
        var t = {};
        for (var e in n) "onLoad" !== e && "onShow" !== e && "onHide" !== e && "onUnload" !== e && "onPullDownRefresh" !== e && "onReachBottom" !== e && "onShareAppMessage" !== e && (t[e] = n[e]);
        return t.onLoad = function(t) {
            i.call(this, t), "function" == typeof n.onLoad && n.onLoad.call(this, t);
        }, t.onShow = function(t) {
            c.call(this), "function" == typeof n.onShow && n.onShow.call(this, t);
        }, t.onHide = function(t) {
            u.call(this), "function" == typeof n.onHide && n.onHide.call(this, t);
        }, t.onUnload = function(t) {
            h.call(this), "function" == typeof n.onUnload && n.onUnload.call(this, t);
        }, t.onReachBottom = function(t) {
            l(), n.onReachBottom && "function" == typeof n.onReachBottom && n.onReachBottom.call(this, t);
        }, t.onPullDownRefresh = function(t) {
            f(), n.onPullDownRefresh && "function" == typeof n.onPullDownRefresh && n.onPullDownRefresh.call(this, t);
        }, n.onShareAppMessage && "function" == typeof n.onShareAppMessage && (t.onShareAppMessage = function(t) {
            var e = n.onShareAppMessage.call(this, t);
            return void 0 === e ? (e = {}, e.path = this.route) : void 0 === e.path && (e.path = this.route), 
            p.call(this, e);
        }), t;
    }
    var b = require("./ald-stat-conf");
    void 0 === wx.Queue && (wx.Queue = new function() {
        this.concurrency = 4, this.queue = [], this.tasks = [], this.activeCount = 0;
        var n = this;
        this.push = function(t) {
            this.tasks.push(new Promise(function(e, o) {
                var a = function() {
                    n.activeCount++, t().then(function(n) {
                        e(n);
                    }).then(function() {
                        n.next();
                    });
                };
                n.activeCount < n.concurrency ? a() : n.queue.push(a);
            }));
        }, this.all = function() {
            return Promise.all(this.tasks);
        }, this.next = function() {
            n.activeCount--, n.queue.length > 0 && n.queue.shift()();
        };
    }(), wx.Queue.all()), "" === b.app_key && console.error("请在ald-stat-conf.js文件中填写小程序统计/广告监测平台创建小程序后生成的app_key，请参考接入文档 http://doc.aldwx.com 小程序统计平台-快速接入指南！"), 
    b.useOpen && console.warn("提示：开启了useOpen配置后，如果不上传用户OpendID则不会上报数据，上传方式：http://doc.aldwx.com 小程序统计/广告监测平台-快速接入指南-上传OpenID！");
    var M = "7.3.6", P = "log", k = "wx", L = void 0 === wx.getAccountInfoSync ? "" : wx.getAccountInfoSync().miniProgram.appId.split("").map(function(n) {
        return n.charCodeAt(0) + 9;
    }).join("-"), R = !1, C = y(), H = "", U = Date.now(), E = 0, j = "", T = function() {
        var n = "";
        try {
            n = wx.getStorageSync("aldstat_op");
        } catch (n) {}
        return n;
    }(), B = "", N = 0, Q = "", J = "", K = function() {
        var n = "";
        try {
            n = wx.getStorageSync("aldstat_uuid");
        } catch (t) {
            n = "uuid_getstoragesync";
        }
        if (n) J = !1; else {
            n = d();
            try {
                wx.setStorageSync("aldstat_uuid", n), J = !0;
            } catch (n) {
                wx.setStorageSync("aldstat_uuid", "uuid_getstoragesync");
            }
        }
        return n;
    }(), G = "", V = "", W = "", $ = 0, z = "", F = "", X = {}, Y = !1, Z = !1, nn = "", tn = "", en = "", on = "", an = !0, rn = !1, sn = "", cn = new function() {
        this.request = [], this.updata = !1, this.push = function(n) {
            this.request.length >= 8 && !this.updata && (this.updata = !0, t()), this.request.length >= 10 ? (this.request.shift(), 
            this.request.push(n)) : this.request.push(n);
        }, this.concat = function() {
            this.request.map(function(n) {
                wx.Queue.push(n);
            }), this.request = [];
        };
    }(), un = 0, hn = 0, fn = !1;
    [ {
        name: "scanCode"
    }, {
        name: "chooseAddress"
    }, {
        name: "chooseImage"
    }, {
        name: "previewImage"
    }, {
        name: "chooseInvoiceTitle"
    }, {
        name: "chooseInvoice"
    } ].forEach(function(n) {
        n.fn = wx[n.name];
        var t = n.name;
        Object.defineProperty(wx, t, {
            get: function() {
                return fn = !0, n.fn;
            }
        });
    });
    var ln = "";
    wx.request({
        url: "https://" + P + ".aldwx.com/config/app.json",
        header: {
            AldStat: "MiniApp-Stat"
        },
        method: "GET",
        success: function(n) {
            200 === n.statusCode && (M < n.data.version && console.warn("您的SDK不是最新版本，部分功能不可用，请尽快前往 http://tj.aldwx.com/downSDK 升级"), 
            n.data.warn && console.warn(n.data.warn), n.data.error && console.error(n.data.error));
        }
    }), wx.aldstat = new e("");
    try {
        var pn = wx.getSystemInfoSync();
        X.br = pn.brand, X.pm = pn.model, X.pr = pn.pixelRatio, X.ww = pn.windowWidth, X.wh = pn.windowHeight, 
        X.lang = pn.language, X.wv = pn.version, X.wvv = pn.platform, X.wsdk = pn.SDKVersion, 
        X.sv = pn.system;
    } catch (n) {}
    return wx.getNetworkType({
        success: function(n) {
            X.nt = n.networkType;
        }
    }), wx.getSetting({
        success: function(n) {
            n.authSetting["scope.userLocation"] ? wx.getLocation({
                type: "wgs84",
                success: function(n) {
                    X.lat = n.latitude, X.lng = n.longitude, X.spd = n.speed;
                }
            }) : b.getLocation && wx.getLocation({
                type: "wgs84",
                success: function(n) {
                    X.lat = n.latitude, X.lng = n.longitude, X.spd = n.speed;
                }
            });
        }
    }), e.prototype.sendEvent = function(t, e) {
        if ("" !== t && "string" == typeof t && t.length <= 255) if ("string" == typeof e && e.length <= 255) q("event", t, e); else if ("object" == (void 0 === e ? "undefined" : n(e))) {
            if (JSON.stringify(e).length >= 255) return void console.error("自定义事件参数不能超过255个字符，请参考接入文档 http://doc.aldwx.com 小程序统计平台-快速接入指南-自定义事件！");
            if (_(e)) return void console.error("事件参数内部只支持Number、String等类型，请参考接入文档 http://doc.aldwx.com 小程序统计平台-快速接入指南-自定义事件！");
            for (var o in e) "number" == typeof e[o] && (e[o] = e[o] + "s##");
            q("event", t, JSON.stringify(e));
        } else void 0 === e ? q("event", t, !1) : console.error("事件参数必须为String、Object类型，且参数长度不能超过255个字符，请参考接入文档 http://doc.aldwx.com 小程序统计平台-快速接入指南-自定义事件！"); else console.error("事件名称必须为String类型且不能超过255个字符，请参考接入文档 http://doc.aldwx.com 小程序统计平台-快速接入指南-自定义事件！");
    }, e.prototype.sendSession = function(n) {
        if ("" !== n && n) {
            j = n;
            var t = g();
            t.tp = "session", t.ct = "session", t.ev = "event", "" === F ? wx.getSetting({
                success: function(n) {
                    n.authSetting["scope.userInfo"] ? wx.getUserInfo({
                        success: function(n) {
                            t.ufo = m(n), B = v(n.userInfo.avatarUrl.split("/")), "" !== z && (t.gid = z), w(t);
                        }
                    }) : "" !== z && (t.gid = z, w(t));
                }
            }) : (t.ufo = F, "" !== z && (t.gid = z), w(t));
        } else console.error("请传入从后台获取的session_key");
    }, e.prototype.sendOpenid = function(n) {
        if ("" !== n && n && 28 === n.length) {
            T = n, wx.setStorageSync("aldstat_op", n);
            var t = g();
            t.tp = "openid", t.ev = "event", t.ct = "openid", w(t);
        } else console.error("OpenID不符合规则，请参考接入文档 http://doc.aldwx.com 小程序统计/广告监测平台-快速接入指南！");
    }, e.prototype.setOpenid = function(n) {
        "function" == typeof n && (ln = n, t());
    }, b.plugin ? {
        App: function(n) {
            return App(O(n));
        },
        Page: function(n) {
            return Page(I(n));
        },
        MpvueApp: function(n) {
            return R = !0, O(n);
        },
        MpvuePage: function(n) {
            return I(n);
        }
    } : void function() {
        var n = App, t = Page, e = Component;
        App = function(t) {
            A(t, "onLaunch", o), A(t, "onShow", a), A(t, "onHide", r), A(t, "onError", s), n(t);
        }, Page = function(n) {
            var e = n.onShareAppMessage;
            A(n, "onLoad", i), A(n, "onUnload", h), A(n, "onShow", c), A(n, "onHide", u), A(n, "onReachBottom", l), 
            A(n, "onPullDownRefresh", f), void 0 !== e && null !== e && (n.onShareAppMessage = function(n) {
                if (void 0 !== e) {
                    var t = e.call(this, n);
                    return void 0 === t ? (t = {}, t.path = nn) : void 0 === t.path && (t.path = nn), 
                    p(t);
                }
            }), t(n);
        }, Component = function(n) {
            try {
                var t = n.methods.onShareAppMessage;
                A(n.methods, "onLoad", i), A(n.methods, "onUnload", h), A(n.methods, "onShow", c), 
                A(n.methods, "onHide", u), A(n.methods, "onReachBottom", l), A(n.methods, "onPullDownRefresh", f), 
                void 0 !== t && null !== t && (n.methods.onShareAppMessage = function(n) {
                    if (void 0 !== t) {
                        var e = t.call(this, n);
                        return void 0 === e ? (e = {}, e.path = nn) : void 0 === e.path && (e.path = nn), 
                        p(e);
                    }
                }), e(n);
            } catch (t) {
                e(n);
            }
        };
    }();
});